package cn.wolfcode.luowowo.acticle.service.impl;


import cn.wolfcode.luowowo.acticle.domain.TravelCommend;
import cn.wolfcode.luowowo.acticle.mapper.TravelCommendMapper;
import cn.wolfcode.luowowo.acticle.query.TravelCommendQuery;
import cn.wolfcode.luowowo.acticle.service.ITravelCommendService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@Service
@Transactional
public class TravelCommendServiceImpl implements ITravelCommendService {
    @Autowired
    private TravelCommendMapper travelCommendMapper;

    @Override
    public PageInfo query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo(travelCommendMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {


        if(travelCommend.getId()  == null){
            travelCommendMapper.insert(travelCommend);
        }else{
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }
    }

    @Override
    public void delete(Long id) {
        travelCommendMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<TravelCommend> getHotTravelCommendTopN(int i) {
        PageHelper.startPage(1, i, " t.sequence ");
        return travelCommendMapper.selectHotTravelCommendTopN();
    }
}
